﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Text;

namespace InternetSpiderLib.Scenes.Actions
{
    public abstract class HtmlBaseDataExtractionAction : ISceneAction
    {
        public void Run(SceneContext data)
        {
            var document = data?.Context?.Get<HtmlDocument>();
            if (document == null)
            {
                var body = data?.Context?.Get<string>(SceneContextKey.HtmlBody);
                if (string.IsNullOrEmpty(body))
                    return;

                document = new HtmlDocument();
                document.LoadHtml(body);

                data?.Context?.Set(document);
            }

            Extraction(data);
        }

        public abstract void Extraction(SceneContext data);
    }
}
